home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / xbtx.lha / Source / IOSerial.hpp < prev    next >
C/C++ Source or Header  |  1995-12-03  |  4KB  |  118 lines

  1. /*
  2. **    $Id: IOSerial.hpp 1.4 1995/12/03 12:16:23 olsen Exp olsen $
  3. **
  4. **    :ts=4
  5. */
  6.  
  7. /*
  8.  * Copyright © 1995 by Olaf Barthel, All Rights Reserved
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
  20.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
  22.  * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  25.  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  27.  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  28.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  *
  30.  * This software has not been validated by the ``Bundesamt fuer Zulassungen in
  31.  * der Telekommunikation'' of the ``Deutsche Bundepost Telekom'' and thus
  32.  * must not be used for accessing the BTX-Network of the Telekom in Germany.
  33.  *
  34.  * Diese Software hat keine Zulassung durch das Bundesamt fuer Zulassungen in
  35.  * der Telekommunikation der Deutschen Bundespost Telekom und darf daher nicht
  36.  * am Netz der Deutschen Bundespost Telekom in Deutschland betrieben werden.
  37.  */
  38.  
  39. #ifndef _IOSERIAL_HPP
  40. #define _IOSERIAL_HPP 1
  41.  
  42. /****************************************************************************/
  43.  
  44. #include <stdarg.h>
  45. #include <stdio.h>
  46.  
  47. /****************************************************************************/
  48.  
  49. #ifndef _TYPES_HPP
  50. #include "Types.hpp"
  51. #endif
  52.  
  53. #ifndef _IOCHANNEL_HPP
  54. #include "IOChannel.hpp"
  55. #endif
  56.  
  57. #ifndef _IORAWSERIAL_HPP
  58. #include "IORawSerial.hpp"
  59. #endif
  60.  
  61. /****************************************************************************/
  62.  
  63. #define BLOCK_BUFFER_SIZE 3000
  64.  
  65. class IOSerial : public IOChannel
  66. {
  67.     public:
  68.  
  69.         IOSerial();
  70.         ~IOSerial();
  71.  
  72.         LONG Open(CONST STRPTR Channel,ULONG Unit=0,ULONG Baud=0,BOOL RTS_CTS=-1);
  73.         VOID Close(VOID);
  74.  
  75.         LONG GetChar(LONG Timeout=0) { return((LONG)modeminput(Timeout)); };
  76.  
  77.         VOID PutChar(UBYTE Char) { PutString((CONST STRPTR)&Char,1); }
  78.         VOID PutString(CONST STRPTR String,LONG Len=-1);
  79.  
  80.         LONG GetCharDirect(LONG Timeout=0) { return(Raw->GetChar(Timeout)); };
  81.         VOID PutCharDirect(UBYTE Char) { Raw->PutChar(Char); };
  82.         VOID PutStringDirect(CONST STRPTR String,LONG Len=-1) { Raw->PutString(String,Len); };
  83.  
  84.         VOID Flush(VOID) { Raw->Flush(); };
  85.  
  86.         LONG Waiting(VOID) { return(buffered + Raw->Waiting()); };
  87.  
  88.         ULONG WaitMask(VOID) { return(Raw->WaitMask()); };
  89.  
  90.         VOID StartProtocol(VOID);
  91.  
  92.     private:
  93.  
  94.         int modeminput(LONG Timeout);
  95.         UWORD getcheck(LONG Timeout);
  96.         inline void send_TFI();
  97.         inline LONG getmodem(LONG Timeout) { return(Raw->GetChar(Timeout)); };
  98.         inline void putmodem(int c) { PutCharDirect((UBYTE)c); };
  99.  
  100.         IORawSerial *Raw;
  101.  
  102.         unsigned int    block, bufferlen;
  103.         unsigned int    tfi;
  104.         UBYTE            buffer[BLOCK_BUFFER_SIZE];
  105.         UBYTE            ack01,status;
  106.         UWORD            crc;
  107.         BOOL            got_dle;
  108.         BOOL            got_itb_bcc;
  109.         BOOL            buffer_input;
  110.  
  111.         LONG            buffered;
  112.         LONG            bufferindex;
  113.  
  114.         UWORD            crctab[256];
  115. };
  116.  
  117. #endif    // _IOSERIAL_HPP
  118.